package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.OrderSettingService;
import com.yoda.mall.model.entity.oms.OrderSetting;
import com.yoda.mall.model.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 12月 19日 9:21
 */
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {

    @Resource
    private OrderSettingService orderSettingService;
    /**
     * 得到订单设置
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/{id}")
    public R getOrderSetting(@PathVariable Long id){
        OrderSetting orderSetting = orderSettingService.getOrderSetting(id);
        return R.success(orderSetting);
    }

    @PostMapping("/update/{id}")
    public R updateOrderSetting(@PathVariable Long id,@RequestBody OrderSetting orderSetting){
        if (Objects.isNull(orderSetting.getId())){
            orderSetting.setId(id);
        }
        Integer count = orderSettingService.updateOrderSetting(orderSetting);
        return R.success(count);
    }
}
